package com.superpeer.baseproject.base;

import android.content.Context;
import android.os.Build;
import android.text.TextUtils;

import com.superpeer.baseproject.baserx.RxManager;


public class BasePresenter<T, E> {
    public Context mContext;
    public E mModel;
    public T mView;
    public RxManager mRxManage = new RxManager();

    public void setVM(T v, E m){
        this.mView = v;
        this.mModel = m;
        this.onStart();
        if(isWifiProxy(mContext)){
            onDestroy();
        }
    }
    public void onStart(){

    }
    public void onDestroy(){
        mRxManage.clear();
    }

    private static boolean isWifiProxy(Context mContext) {
        final boolean IS_ICS_OR_LATER = Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
        String proxyAddress;
        int proxyPort;
        if (IS_ICS_OR_LATER) {
            proxyAddress = System.getProperty("http.proxyHost");
            String portStr = System.getProperty("http.proxyPort");
            proxyPort = Integer.parseInt((portStr != null ? portStr : "-1"));
        } else {
            proxyAddress = android.net.Proxy.getHost(mContext);
            proxyPort = android.net.Proxy.getPort(mContext);
        }
        return (!TextUtils.isEmpty(proxyAddress)) && (proxyPort != -1);
    }
}
